package com.wzu.rjgc_ks.controller;

import com.sun.javafx.collections.MappingChange;
import com.wzu.rjgc_ks.dao.CompanyMapper;
import com.wzu.rjgc_ks.pojo.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Controller
@RequestMapping("/company")
public class ComAdminAction {

    @Autowired
    CompanyMapper companyMapper;

    @RequestMapping("/admin")
    public String model(ModelMap modelMap){
        return "model";
    }

    @RequestMapping("/queryAll")
    public String queryAll(ModelMap modelMap){
        List<Company> list = companyMapper.selectChecked();
        List<Company> list2 = companyMapper.selectNoChecked();
        modelMap.addAttribute("comlist", list);
        modelMap.addAttribute("comnolist", list2);

        return "admin/company/company_list";
    }

    @RequestMapping("/queryCheck")
    public String queryCheck(ModelMap modelMap){
        List<Company> list = companyMapper.selectCheck();
        modelMap.addAttribute("comlist", list);

        return "admin/company/company_check";
    }

    @RequestMapping("/reset")
    public String reset(@RequestParam(value = "comId") Integer comId, ModelMap modelMap){
        //reset PWD
        Company company = new Company();
        company.setComId(comId);
        companyMapper.updatePWDByPrimaryKey(company);
        return "success";
    }

    @RequestMapping("/del")
    @ResponseBody
    public String del(@RequestParam(value = "comId") Integer comId, ModelMap modelMap){
        companyMapper.deleteByPrimaryKey(comId);
        return "success";
    }

    @RequestMapping("/check")
    public String check(@RequestParam(value = "comId") Integer comId,
                        @RequestParam(value = "comCheckReason") String comCheckReason,
                        @RequestParam(value = "comCheckSign") String comCheckSign, ModelMap modelMap){
        Company company = new Company();
        company.setComCheckTime(new Date());
        company.setComId(comId);
        company.setComCheckSign(comCheckSign);
        company.setComCheckReason(comCheckReason);
        company.setComCheckId(2);

        companyMapper.updateCheckByPrimaryKey(company);
        return "success";
    }
}
